package hauwei.exam416;

import java.util.*;

public class MinSubway {
    static int minCount=Integer.MAX_VALUE;
    static String minPath="";
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int lines=scanner.nextInt();
        scanner.nextLine();
        List<HashSet<String>>subwayLines=new ArrayList<>(lines);
        for (int i = 0; i < lines; i++){
            String[]line=scanner.nextLine().split(" ");
            //subwayLines.add(new HashSet<>(List.of(line)));
        }
        String[] startEnd = scanner.nextLine().split(" ");
        String start=startEnd[0];
        String end=startEnd[1];
        scanner.close();
        for(int i=0;i<subwayLines.size();i++){
            HashSet<String> set = subwayLines.get(i);
            if(set.contains(start)){
                ArrayList<String> path = new ArrayList<>();
                path.add(start);
                dfs(i,end,subwayLines,new int[lines],2,path);
            }
        }
        if(minPath.isEmpty()){
            System.out.println("NA");
        }else{
            System.out.println(minPath);
            System.out.println(minCount);
        }
    }
    public static void dfs(int index,String end,List<HashSet<String>>subwayLines,int []visited,int count,List<String>path){
        visited[index]=1;
        HashSet<String> set = subwayLines.get(index);
        if(set.contains(end)){
            if(count<minCount){
                path.add(end);
                minCount=count;
                minPath=String.join("-",path);
            }
            return;
        }

        for(String station:set){
            for(int i=0;i<subwayLines.size();i++){
                if(visited[i]==0&&subwayLines.get(i).contains(station)&&!path.contains(station)){
                    path.add(station);
                    dfs(i,end,subwayLines,visited,count+1,new ArrayList<>(path));
                    path.remove(station);
                }
            }
        }
        visited[index]=0;
    }
}
